﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Data.SqlClient;

namespace K36_104_047_NguyenVanCaoNguyen
{
    class UIDToString : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                SqlConnection conn = new SqlConnection(Properties.Settings.Default.ConnStr);
                SqlCommand cmd = new SqlCommand("SELECT uname FROM Usages WHERE uid =" + value.ToString(), conn);
                try
                {
                    conn.Open();
                    return (string)cmd.ExecuteScalar();
                }
                catch
                {
                    return String.Empty;
                }
            }
            else
            {
                return String.Empty;
            }
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    class TIDToString : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                SqlConnection conn = new SqlConnection(Properties.Settings.Default.ConnStr);
                SqlCommand cmd = new SqlCommand("SELECT tname FROM Types WHERE tid =" + value.ToString(), conn);
                try
                {
                    conn.Open();
                    return (string)cmd.ExecuteScalar();
                }
                catch
                {
                    return String.Empty;
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                return String.Empty;
            }
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    class PIDToString : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                SqlConnection conn = new SqlConnection(Properties.Settings.Default.ConnStr);
                SqlCommand cmd = new SqlCommand("SELECT pname FROM Patients WHERE pid =" + value.ToString(), conn);
                try
                {
                    conn.Open();
                    return (string)cmd.ExecuteScalar();
                }
                catch
                {
                    return String.Empty;
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                return String.Empty;
            }
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
